<?php

	session_start();

	require_once("appconf.php");
	require_once("lib/utility.php");

	if(!isset($_SESSION['username'])) {
		header("HTTP/1.1 401 Unauthorized");
		die();
	}



	$realm 		= $_REQUEST["realm"];
	$filename 	= $_REQUEST["file"];

	if ($filename && $realm) {

		if ($realm == "report") {
			$filepath = $appRoot."data/".filenameSafe($_SESSION['username'])."/reports/".$filename;

			@unlink($filepath);

			//Also delete content directory
			if (endsWith($filepath, ".xml")) {
				$contentDir = substr($filepath, 0, strlen($filepath)-4);
				@rm_recursive($contentDir);
			}

		} else {
			$filepath = $appRoot."data/".filenameSafe($_SESSION['username'])."/templates/".$filename;

			@unlink($filepath);
		}

		header("HTTP/1.1 200 OK");
		die();
	}

	header("HTTP/1.1 400 Bad Request");
?>